package com.yqg.education.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yqg.education.common.Result;
import com.yqg.education.controller.dto.ExamAnswerDetailDTO;
import com.yqg.education.entity.ExamAnswerDetail;
import com.yqg.education.entity.Question;
import com.yqg.education.mapper.ExamSignMapper;
import com.yqg.education.mapper.ExamquestionMapper;
import com.yqg.education.mapper.QuestionMapper;
import com.yqg.education.service.IExamAnswerDetailService;
import com.yqg.education.service.IQuestionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * ExamAnswerDetailController 前端控制器
 * @author 张芸博
 * @since 2025-04-10
 */
@RestController
@RequestMapping("/exam-answer-detail")
public class ExamAnswerDetailController {

    @Resource
    private IExamAnswerDetailService examAnswerDetailService;

    /**
    *  新增或者更新
    */
    @PostMapping("/edit")
    public Result save(@RequestBody ExamAnswerDetail examAnswerDetail) {
        return Result.success(examAnswerDetailService.saveOrUpdate(examAnswerDetail));
    }
    /**
    *  删除
    */
    @GetMapping("delete/{id}")
    public Result delete(@PathVariable Integer id) {
        ExamAnswerDetail examAnswerDetail =examAnswerDetailService.getById(id);
        return Result.success(examAnswerDetailService.saveOrUpdate(examAnswerDetail));
    }
    /**
    *  查询所有
    */
    @GetMapping("/all")
    public Result findAll() {
        QueryWrapper<ExamAnswerDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
       List<ExamAnswerDetail> list=  examAnswerDetailService.list(queryWrapper);
        return Result.success(list);
    }
    /**
    *  根据id查询
    */
    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(examAnswerDetailService.getById(id));
    }
    /**
    *  分页查询
    */
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                                @RequestParam Integer pageSize) {
        QueryWrapper<ExamAnswerDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete", "0");
        queryWrapper.orderByDesc("id");
        return Result.success(examAnswerDetailService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

    /**
     * 学员端交卷接口实现
     */
    @PostMapping("/stuSubmitExampaper")
    public Result stuSubmitExampaper(@RequestBody ExamAnswerDetailDTO examAnswerDetailDTO){
        examAnswerDetailService.stuSubmitExampaper(examAnswerDetailDTO);
        return Result.success();
    }

}

